<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/functions" prefix="fn" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt"%> 
<c:set var="ctx" value="${pageContext.request.contextPath }" />
<link rel="stylesheet"
	href="${ctx }/resources/js/select2/select2.min.css" />
<script type="text/javascript"
	src="${ctx }/resources/js/select2/select2.min.js"></script>
<script type="text/javascript"
	src="${ctx }/resources/js/select2/zh-CN.js"></script>
	<script type="text/javascript">
$(function() {
	webside.form.banner.BannerForm();
})
</script>
<script src="${ctx }/resources/js/upload/ajaxfileupload.js"
	type="text/javascript">
	
</script>
<script type="text/javascript"> 

function uploadVideoResource() {
    var fileName = $("#cover").val();
    var type = fileName.split(".");
    var ftype = type[type.length - 1]; //获取文件后缀
    $.ajaxFileUpload({
        url: '${ctx }/files/upload/' + ftype,
        secureuri: false, //是否需要安全协议，一般设置为false
        fileElementId: ['cover'], //文件上传域的ID
        dataType: 'json', //返回值类型 一般设置为json
        success: function (data, status) //服务器成功响应处理函数
        {
        	 
            if (data.result == 0) {
            	var fileId = data.data[0].id;
            	var filePath = '/files/view/jpg/' + fileId;
            	$("#hiddenResourceUrl").val(filePath);
            	//显示图片
				$("#imgCover").attr("src",'${ctx}/files/view/jpg/' + fileId);
				//显示名字
				$("#labcover").html(data.data[0].name);
            }
        },
        error: function (data, status, e) //服务器响应失败处理函数
        {
            alert("上传失败："+e);
        }
    });
}
</script>

<style>
.iconShow
{
	padding-left: 10px; 
	padding-top: 3px;
}
.source-icon
{
	 width:95%;
	 float:left;
}
@media screen and (max-width: 374px){
	.source-icon
	{
		 width:82%;
	}
}
@media screen and (min-width: 375px) and (max-width: 449px){
	.source-icon
	{
		 width:85%;
	}
}
@media screen and (min-width: 450px) and (max-width: 1279px) {
	.source-icon
	{
		 width:90%;
	}
}
@media screen and (min_width: 1280px) {
	.source-icon
	{
		 width:90%;
	}
}
</style>
<div class="page-header">
	<h1>
		<c:if test="${empty bannerEntity}">
		新增Banner
		</c:if>
		<c:if test="${!empty bannerEntity}">
		编辑Banner
		</c:if>
	</h1>
</div>
<div class="row" style="margin-top: 5px;">
	<div class="col-xs-12">
		<form id="bannerForm" name="bannerForm" class="form-horizontal" role="form" method="post">
			<c:if test="${!empty bannerEntity}">
				<input type="hidden" id="pageNum" name="pageNum" value="${page.pageNum }"> 
				<input type="hidden" id="pageSize" name="pageSize" value="${page.pageSize }"> 
				<input type="hidden" id="orderByColumn" name="orderByColumn" value="${page.orderByColumn }"> 
				<input type="hidden" id="orderByType" name="orderByType" value="${page.orderByType }">
				<input type="hidden"  id='id' name="id" value="${bannerEntity.id }">
			</c:if>
			<div class="form-group">
				<label class="control-label col-sm-2 no-padding-right" for="title">标题：</label>
				<div class="col-sm-8">
				<div class="clearfix">
					<input class="form-control" name="title" id="title" type="text"
						value="${bannerEntity.title }" placeholder="" />
                </div>
				</div>
            </div>
		<div class="form-group">
			<label class="control-label col-sm-2 no-padding-right" for="cover">封面：</label>
			<div class="col-sm-8">
				<div class="clearfix">
					<input class="form-control" name="files" id="cover" type="file"
		                  value="${bannerEntity.imgUrl }" placeholder="封面..." />
		                 <img id="imgCover" alt="" 
		                 <c:if test="${null eq  bannerEntity.imgUrl}">src="${ctx}/resources/images/xx.png"</c:if> 
		                 <c:if test="${bannerEntity.imgUrl != null}">src="${ctx}${bannerEntity.imgUrl}"</c:if>
		                  width="175px" height="100px">
						<label id="labcover" ></label>                
					<input class="btn btn-primary btn-sm" type="button" value="上传" onclick="javascript:uploadVideoResource();"/>
					 <input id="hiddenResourceUrl" name="imgUrl" type="hidden" />
				 </div>
			</div>
		</div>	
		<div class="form-group">
				<label class="control-label col-sm-2 no-padding-right" for="summary">描述：</label>
				<div class="col-sm-8">
				<div class="clearfix">
					<input class="form-control" name="summary" id="summary" type="text"
						value="${bannerEntity.summary }" placeholder="" />
                </div>
				</div>
            </div>
			<div class="form-group">
				<label class="control-label col-sm-2 no-padding-right" for="channel">频道</label>
				<div class="col-sm-8">
				<div class="clearfix">
					<select id="channel" class="form-control" name='channel'>
						    <option typecode="" value="" <c:if test="${bannerEntity.channel eq null}">selected="selected"</c:if>>请选择</option>
						    <option typecode="" value="INDEX" <c:if test="${bannerEntity.channel eq 'INDEX'}">selected="selected"</c:if>>首页</option>
							<c:forEach items="${channelList}" var="t">
							<option typecode="${t.code }" value="${t.code}"<c:if test="${bannerEntity.channel eq t.code}">selected="selected"</c:if>>${t.name}</option>
							</c:forEach>
						</select>
                </div>
				</div>
            </div>	
			 
			<div class="form-group">
				<label class="control-label col-sm-2 no-padding-right" for="linkUrl">链接地址：</label>
				<div class="col-sm-8">
				<div class="clearfix">
					<input class="form-control" name="linkUrl" id="linkUrl" type="text"
						value="${bannerEntity.linkUrl }" placeholder="链接地址，例如：http://00.00.00.00:0000/webside-huoyan-manage/index.html" />
                </div>
				</div>
            </div>
            <input type="hidden"  id='target' name="target" value="BANNER">
          
            <div class="form-group">
				<label class="control-label col-sm-2 no-padding-right" 
				for="sort">排序</label>
				<div class="col-sm-8">
				<div class="clearfix">
				<input class="form-control" name="sort"  id="sort" 
				 type="text" value="${bannerEntity.sort }" placeholder="排序" onkeyup="value=value.replace(/[^(\d)]/g,'')"/>
				 <label>只能写(1-10)</label>
				</div>
				</div>
			</div>
	
			 
		</form>
		<div class="hr hr-dotted"></div>
	</div>
</div>
<div class="center">
	<button id="btnAdd" type="button" 
	onclick="javascript:$('#bannerForm').submit();" 
	class="btn btn-success btn-sm">
		<i class="fa fa-user-plus"></i>&nbsp;
		<c:if test="${empty bannerEntity}">
		添加
		</c:if>
		<c:if test="${!empty bannerEntity}">
		保存
		</c:if>
	</button>
	<button id="btn" type="button"
		onclick="webside.common.loadPage('/banner/listUI.html<c:if test="${!empty bannerEntity}">?page=${page.pageNum }&rows=${page.pageSize }&sidx=${page.orderByColumn }&sord=${page.orderByType }</c:if>')"
		class="btn btn-info btn-sm">
		<i class="fa fa-undo"></i>&nbsp;返回
	</button>
</div>
 